package com.youlai.boot.modules.tp.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
 * 供应链看板数据VO
 *
 * @author Jason
 * @since 2025-06-04
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "供应链看板数据")
public class SupplyChainDashboardVO {

    @Schema(description = "概览指标")
    private OverviewMetrics overviewMetrics;

    @Schema(description = "库存分析")
    private InventoryAnalysis inventoryAnalysis;

    @Schema(description = "周转分析")
    private TurnoverAnalysis turnoverAnalysis;

    @Schema(description = "目标达成")
    private TargetAchievement targetAchievement;

    @Schema(description = "店铺表现排行")
    private List<StorePerformance> storePerformanceList;

    @Schema(description = "库存预警")
    private List<InventoryAlert> inventoryAlerts;

    @Schema(description = "趋势数据")
    private TrendData trendData;

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "概览指标")
    public static class OverviewMetrics {
        @Schema(description = "总库存金额（万元）")
        private BigDecimal totalInventoryAmount;

        @Schema(description = "总库存数量（箱）")
        private Integer totalInventoryQuantity;

        @Schema(description = "现货金额（万元）")
        private BigDecimal spotAmount;

        @Schema(description = "在途金额（万元）")
        private BigDecimal inTransitAmount;

        @Schema(description = "平均周转天数")
        private Integer avgTurnoverDays;

        @Schema(description = "预警商品数量")
        private Integer alertProductCount;

        @Schema(description = "活跃店铺数")
        private Integer activeStoreCount;

        @Schema(description = "PV现货率（%）")
        private BigDecimal pvSpotRate;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "库存分析")
    public static class InventoryAnalysis {
        @Schema(description = "现货占比（%）")
        private BigDecimal spotRatio;

        @Schema(description = "在途占比（%）")
        private BigDecimal inTransitRatio;

        @Schema(description = "库存结构健康度")
        private String inventoryHealthStatus;

        @Schema(description = "库存分布数据")
        private List<InventoryDistribution> distributionData;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "库存分布")
    public static class InventoryDistribution {
        @Schema(description = "类别")
        private String category;

        @Schema(description = "金额（万元）")
        private BigDecimal amount;

        @Schema(description = "占比（%）")
        private BigDecimal percentage;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "周转分析")
    public static class TurnoverAnalysis {
        @Schema(description = "快周转商品数（<30天）")
        private Integer fastTurnoverCount;

        @Schema(description = "中周转商品数（30-60天）")
        private Integer mediumTurnoverCount;

        @Schema(description = "慢周转商品数（>60天）")
        private Integer slowTurnoverCount;

        @Schema(description = "周转效率环比（%）")
        private BigDecimal turnoverEfficiencyChange;

        @Schema(description = "最佳周转店铺")
        private String bestTurnoverStore;

        @Schema(description = "最佳周转天数")
        private Integer bestTurnoverDays;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "目标达成")
    public static class TargetAchievement {
        @Schema(description = "本月NR目标（万元）")
        private BigDecimal monthlyNrTarget;

        @Schema(description = "已下单金额（万元）")
        private BigDecimal orderedAmount;

        @Schema(description = "达成率（%）")
        private BigDecimal achievementRate;

        @Schema(description = "预计完成时间")
        private LocalDate estimatedCompletionDate;

        @Schema(description = "目标状态")
        private String targetStatus;

        @Schema(description = "距离目标差额（万元）")
        private BigDecimal targetGap;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "店铺表现")
    public static class StorePerformance {
        @Schema(description = "ID")
        private Long id;
        
        @Schema(description = "店铺名称")
        private String storeName;

        @Schema(description = "库存金额（万元）")
        private BigDecimal inventoryAmount;

        @Schema(description = "周转天数")
        private Integer turnoverDays;

        @Schema(description = "达成率（%）")
        private BigDecimal achievementRate;

        @Schema(description = "PV现货率（%）")
        private BigDecimal pvSpotRate;

        @Schema(description = "排名")
        private Integer ranking;

        @Schema(description = "趋势")
        private String trend; // up, down, stable
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "库存预警")
    public static class InventoryAlert {
        @Schema(description = "店铺名称")
        private String storeName;

        @Schema(description = "预警类型")
        private String alertType; // low_stock, overstock, slow_turnover

        @Schema(description = "预警级别")
        private String alertLevel; // high, medium, low

        @Schema(description = "预警描述")
        private String alertDescription;

        @Schema(description = "预计缺货天数")
        private Integer estimatedStockoutDays;

        @Schema(description = "建议行动")
        private String recommendedAction;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "趋势数据")
    public static class TrendData {
        @Schema(description = "库存金额趋势")
        private List<TrendPoint> inventoryAmountTrend;

        @Schema(description = "周转天数趋势")
        private List<TrendPoint> turnoverDaysTrend;

        @Schema(description = "达成率趋势")
        private List<TrendPoint> achievementRateTrend;
    }

    @Data
    @Builder
    @NoArgsConstructor
    @AllArgsConstructor
    @Schema(description = "趋势点")
    public static class TrendPoint {
        @Schema(description = "日期")
        private LocalDate date;

        @Schema(description = "值")
        private BigDecimal value;

        @Schema(description = "标签")
        private String label;
    }
} 